#include "stdafx.h"
#include "VoidScene.h"
#include "Block.h"

bool VoidScene::DoInit()
{
	Enable = true;

	if ( !m_font.Create("../Media/consola.ttf", 40, 1000) )
		return false;
	m_font.SetText(L"0000");
	m_font.SetColor(1.0f, 0.0f, 1.0f);

	if ( !m_world.Init() )
		return false;

	if ( !m_zbar.Init() )
		return false;

	m_fps.Init();

	return true;
}

bool VoidScene::DoRun()
{
	m_fps.Frame();

	if ( GameConfig::Get().resize )
	{
		m_cam.Resize();
		GameConfig::Get().resize = false;
	}

	m_world.Draw(m_cam.GetZ());
	m_zbar.Draw();

	wchar buffer[32];
	_itow_s(m_fps.GetFps(), buffer, sizeof(buffer), 10);
	m_font.SetText(buffer);
	m_font.Draw(12, 24);
	return true;
}

void VoidScene::DoClose()
{
	Enable = false;
	m_zbar.Destroy();
	m_world.Destroy();

	m_font.Destroy();	
}

bool VoidScene::MouseScroll(sint scroll)
{
	m_cam.SelectZ(-scroll);
	return true;
}

bool VoidScene::Key(int key, int, eStateAction action, eMODE)
{
	if ( action == eStateAction::ACTION_PRESS || action == eStateAction::ACTION_REPEAT )
	{
		if ( key == KEY_LEFT )
			m_cam.AddPos(-1, 0);
		else if ( key == KEY_RIGHT )
			m_cam.AddPos(1, 0);
		else if ( key == KEY_UP )
			m_cam.AddPos(0, -1);
		else if ( key == KEY_DOWN )
			m_cam.AddPos(0, 1);

	}
	return true;
}